﻿Imports System.Data.SqlClient

Public Class frmVoucherPrint

    Private Sub txtMoveNo_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMoveNo.KeyUp
        If e.KeyCode = Keys.Enter Then
            Me.ErrProv.Clear()

            If Len(Me.txtMoveNo.Text) = 0 Then
                Me.ErrProv.SetError(Me.txtMoveNo, "Please enter voucher no.")
                Me.txtMoveNo.Focus()
                Exit Sub
            Else
                ShowVoucher()
                Me.txtMoveNo.Focus()
            End If
        End If
    End Sub

    Sub ShowVoucher()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim dap As New SqlDataAdapter("select * From Transactions Where MoveNo=" & Me.txtMoveNo.Text.Trim & _
                                          " and Year(TransDate)= " & Me.DTPYear.Value.Year, cnn)
            Dim das As New DataSet

            cnn.Open()
            dap.Fill(das, "Transactions")
            cnn.Close()

            Dim rpt As New Voucher
            rpt.SetDataSource(das)
            Me.CrystalReportViewer1.ReportSource = rpt

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
        End Try
    End Sub

    Private Sub frmVoucherPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
    End Sub
End Class